home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 172 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: clamage@Eng.Sun.COM (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Incompatibility C++ <-> ANSI-C
  5. Date: 30 Jan 1996 09:52:47 PST
  6. Organization: Sun Microsystems Inc.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4elhk6$ai1@engnews1.Eng.Sun.COM>
  9. References: <4ekpnj$h7q@fsuj01.rz.uni-jena.de>
  10. Reply-To: clamage@Eng.Sun.COM
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 30 Jan 1996 16:39:34 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMQ5bAky4NqrwXLNJAQHUdAH/Tq7TLTumpIBlH7ypFUswnPovHKrOc3RM
  15.     GPGRjfdTcH1TfnZeUQRcyAMyNL1FH0J6XfKyDrxkAXX5dIuy+iUHrg==
  16.     =uMPv
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article h7q@fsuj01.rz.uni-jena.de, mkt@isun04.inf.uni-jena.de (Tilo Koerbs) writes:
  20. >Does the operator ?: an itegral promotion on its
  21. >second and third operand in C++?
  22. >I cannot find the answer in the ARM. (I think it says: no)
  23.  
  24. >Consider this:
  25. >char x, y;
  26. >Which type has the following expression:
  27. >(a ? x : y)
  28. >
  29. >In ANSI-C the type is clearly an 'int' (or 'unsigned').
  30. >But the type in C++ is 'char'???
  31.  
  32. Yes, char. If the second and third operands ('x' and 'y' in the example)
  33. have the same type, that is also the result type. Otherwise the usual
  34. conversions are performed to bring them to a common type. In addition,
  35. if the operands are lvalues, the result is also an lvalue.
  36.  
  37. These are differences from C. The different rule means that you can
  38. get the expected overloaded function in a call like
  39.     foo( B ? x : y );
  40. and that references behave properly. As a side effect, you can also write
  41.     (B ? x : y) = 12; // assign 12 to x or y
  42. I'm not sure that is an advantage, however. :-)
  43. ---
  44. Steve Clamage, stephen.clamage@eng.sun.com
  45. ---
  46. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  47.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  48.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  49.